package com.woniuxy.microseckillserver.mapper;

import com.woniuxy.microcommonserver.bean.seckill_lk.SeckillGoodsInfo;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: 刘康
 * @Date: 2021/1/22 10:11
 * @Description:
 */
@Mapper
public interface SeckillMapper {

    /**
     * 新增秒杀商品
     * @param seckillGoodsInfo
     */
    @Options(useGeneratedKeys = true,keyProperty = "s.id")
    @Insert("insert into seckill_goods_info (start_time,end_time,seckill_price,stock,status,is_delete,fk_goods_id) values " +
            "(#{s.startTime},#{s.endTime},#{s.seckillPrice},#{s.stock},0,0,#{s.goodsInfo.id})")
    void saveSeckillGoods (@Param("s") SeckillGoodsInfo seckillGoodsInfo);

    /**
     * 修改秒杀商品
     * @param seckillGoodsInfo
     */
    void updateSeckillGoods (@Param("s") SeckillGoodsInfo seckillGoodsInfo);

    /**
     * 查询所有
     * @param pageRequest
     * @return
     */
    @Select("select id,start_time startTime,end_time endTime,seckill_price seckillPrice,stock,status," +
            "fk_goods_id goodsInfo.id from seckill_goods_info where is_delete = 0 order by ${p.sort} ${p.sortOrder}")
    List<SeckillGoodsInfo> findAll(@Param("p") PageRequest pageRequest);


    /**
     * id查询
     * @param id
     * @return
     */
    @ResultType(SeckillGoodsInfo.class)
    @Select("select id,stock from seckill_goods_info where id = #{id}")
    SeckillGoodsInfo getOneById(@Param("id") Long id);
}
